package top.yxqz.spring.proxy.staticproxy;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author: 余小小
 * @date: 2023/4/13
 * @description：静态代理类：他的功能和目标类一样
 * 实现日志织入功能
 */
@Component("calculatorStaticProxy")
public class CalculatorStaticProxy implements Calculator {
    @Autowired
    private Calculator calculator; //CalculatorImpl

    @Override
    public int add(int i, int j) {
        System.out.println("参数是：" + i + "," + j);

        int result = calculator.add(i, j); //核心代码

        System.out.println("结果是：" + result);
        return result;
    }

    @Override
    public int sub(int i, int j) {
        System.out.println("参数是：" + i + "," + j);
        int result = calculator.sub(i, j); //核心代码
        System.out.println("结果是：" + result);
        return result;
    }

    @Override
    public int mul(int i, int j) {
        System.out.println("参数是：" + i + "," + j);
        int result = calculator.mul(i, j); //核心代码
        System.out.println("结果是：" + result);
        return result;
    }

    @Override
    public int div(int i, int j) {
        System.out.println("参数是：" + i + "," + j);
        int result = calculator.div(i, j); //核心代码
        System.out.println("结果是：" + result);
        return result;
    }
}
